package bma.common.netty.protobuf.common.impl;

import bma.common.langutil.pipeline.CommonPipelineAbstract;
import bma.common.netty.protobuf.common.PRequestFilter;
import bma.common.netty.protobuf.core.PRequestContext;

public abstract class PRequestFilterPipeline extends
		CommonPipelineAbstract<PRequestFilter, PRequestFilterPipelineContext> {

	public abstract boolean processRequest(PRequestContext ctx);

	public boolean process(PRequestContext ctx) {
		PRequestFilterPipelineContext pctx = getHead();
		if (pctx != null) {
			return pctx.process(ctx);
		}
		return processRequest(ctx);
	}

	@Override
	protected PRequestFilterPipelineContext newPipelineContext(
			PRequestFilterPipelineContext prev,
			PRequestFilterPipelineContext next, String name, PRequestFilter item) {
		return new PRequestFilterPipelineContext(prev, next, name, item) {
			@Override
			public boolean processEnd(PRequestContext ctx) {
				return processRequest(ctx);
			}
		};
	}
}
